﻿using System;
using System.Data;
using libsharp;
using libexcel;

namespace libwutong
{
    class Program
    {
        static void Main(string[] args)
        {
            const string s_strFolder = "处理结果/";
            const string s_strFileName = "总参考表.xlsx";

            Console.WriteLine(" Made in China by 挨踢狼\n");
            ConsoleSharp.continueByAnykey();
            
            if(false)
            {
                MyExcel.combineTableDate(true);
                Console.WriteLine(" 处理完毕");
                for (; ; ) ;
            }

            MyTxt.print();
            ConsoleSharp.continueByAnykey();
            new TxtWeight().print();
            ConsoleSharp.continueByAnykey();

            DataTable tableRefer;
            string str = s_strFolder + s_strFileName;
            if (System.IO.File.Exists(str))
            {
                new TxtPrice().print();
                ConsoleSharp.continueByAnykey();
                new MyPrice().print();
                ConsoleSharp.continueByAnykey();
                new TxtAreaSupple().print();
                ConsoleSharp.continueByAnykey();

                Console.WriteLine(" 读取 {0}", str);
                tableRefer = ExcelHelper.getTable(str);
            }
            else
            {

                Console.Write(" 生成 {0}.", str);
                tableRefer = MyRefer.getTableRefer("编号查询/", s_strFolder + "违规与不明.txt", true);
                ExcelHelper.writeExcel(tableRefer, str);
                ConsoleSharp.continueByAnykey();

                new TxtPrice().print();
                ConsoleSharp.continueByAnykey();
                new MyPrice().print();
                ConsoleSharp.continueByAnykey();
                new TxtAreaSupple().print();
            }
            ConsoleSharp.continueByAnykey();

            str = s_strFolder + "中转费表.xlsx";
            DataTable tableTransit2;
            DataTable tableTransit = MyExcel.getTransitsFromRefer(tableRefer, out tableTransit2);
            ExcelHelper.writeExcel(tableTransit, str, 5, 6);
            Console.WriteLine(" 导出 {0}",str);


            str = s_strFolder + "汇总.xlsx";
            DataTable tableSummary = MyExcel.getSummaryFromTransit(tableTransit);
            ExcelHelper.writeExcel(tableSummary, str, 1, 2, 3);
            Console.WriteLine(" 导出 {0}", str);


            str = s_strFolder + "无法处理.xlsx";
            if(tableTransit2.Rows.Count > 0)
            {
                ExcelHelper.writeExcel(tableTransit2, str, 5, 6);
                Console.WriteLine(" 导出 {0}", str);
            }
            else if (System.IO.File.Exists(str))
            {
                System.IO.File.Delete(str);
            }


            Console.WriteLine(" 处理完毕");
            for (; ; ) ;
         }
    }
}
